//
//  GFSearchFoodCell.m
//  GoodFood
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 荣伟峰. All rights reserved.
//

#import "GFSearchFoodCell.h"

@interface GFSearchFoodCell ()
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIImageView *foodImage;
@end

@implementation GFSearchFoodCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.nameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.nameLabel];
      
        
        self.foodImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.foodImage];


        
    }
    
    return self;
}


- (void)setDeModel:(GFDetialsModel *)deModel {
    
    if (_deModel != deModel) {

        _deModel = deModel;
    }
    
    //    NSLog(@"%@---------------", self.highLightWord);
    /* 关键字高亮 */
    NSRange range =[deModel.name rangeOfString:self.highLightWord];
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:deModel.name];
    [attribute addAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} range:range];
    [self.nameLabel setAttributedText:attribute];
    if (deModel.thumb_image_url) {
        [self.foodImage setImageWithURL:[NSURL URLWithString:deModel.thumb_image_url] placeholderImage:[UIImage imageNamed:@"category_1"]];
    }

    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.nameLabel.frame = CGRectMake(ScreenWidth / 375 * 60, ScreenWidth / 375 * 10, ScreenWidth / 375 * 300, ScreenWidth / 375 * 30);
    
    self.foodImage.frame = CGRectMake(ScreenWidth / 375 * 10, ScreenWidth / 375 * 5, ScreenWidth / 375 * 40, ScreenWidth / 375 * 40);
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
